package org.duang.db.sql.parser.encode;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;
import org.duang.db.IdEntity;
import org.duang.db.sql.SqlObject;

public class SqlPropertyEncoder extends SqlEncoder {

	public SqlPropertyEncoder(String key, String opt, Object obj) {
		super(key, opt, obj);
	}

	@Override
	public  List<SqlObject> getValue() {
		SqlObject sqlObj = new SqlObject();
		StringBuilder sql = new StringBuilder();
		List<Object> params = new ArrayList<Object>(1);
		sql.append(key).append(getOpt()).append("?");
		if(key.equals(IdEntity.ID_FIELD)){
			params.add(((ObjectId)obj).toString());
		} else {
			params.add(obj);
		}
		sqlObj.setSql(sql.toString());
		sqlObj.setParams(params);
		List<SqlObject> sqlObjectList =  new ArrayList<SqlObject>(1);
		sqlObjectList.add(sqlObj);
		return sqlObjectList;
	}

}
